import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { ObjCreate } from "../../common/ObjCreate";
import { NormalBgItem } from "./NormalBgItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalSkin } from "../../../../component/skin/GlobalSkin";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GuildUnionPosition } from "./rule/GuildUnionPosition";
import { SMiniGuildInfo } from "../../../../../Message/Game/SMiniGuildInfo";
import { Cache } from "../../../cache/Cache";
import { EGuildUnionStatus } from "../../../../../Message/Game/EGuildUnionStatus";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GBitmap } from "../../../../../com/mui/controls/GBitmap";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { _guildInfo } from "../../../../../this/_guildInfo";
import { _allocate } from "../../../../../this/_allocate";
type int = number;
//class GuildUnionGuildItem
    
    export  class GuildUnionGuildItem extends GSprite
    {
        constructor(arg1: int)
        {
            super();
            this._position = arg1;
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            this._bg = ObjCreate.createGBitmap(null, 0, 0, this);
            this._mainBm = ObjCreate.createGBitmap(null, 15, 10, this);
            this._icon = new NormalBgItem();
            this._icon.x = 63;
            this._icon.y = 10;
            this.addChild(this._icon);
            this._contentSp = new GSprite();
            this.addChild(this._contentSp);
            var loc1=GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat6);
            this._guildName = ObjCreate.createGTextField("", 0, 80, 186, 20, this._contentSp, loc1);
            loc1.color = GlobalStyle.color1Uint;
            loc1.align = flash.text.TextFormatAlign.LEFT;
            this._leaderName = ObjCreate.createGTextField("", 10, 99, 176, 20, this._contentSp, loc1);
            this._guildLevel = ObjCreate.createGTextField("", 10, 118, 176, 20, this._contentSp, loc1);
            this._menberNum = ObjCreate.createGTextField("", 10, 137, 176, 20, this._contentSp, loc1);
            loc1.color = GlobalStyle.color6Uint;
            loc1.font = FontUtil.stXingkaiName;
            loc1.size = 16;
            this._incomeLocate = ObjCreate.createGTextField("利益分配：", 8, 156, 176, 20, this._contentSp, loc1);
            this._operBtn1 = ObjCreate.createGButton("解散同盟", 16, 183, 70, 26, this, GlobalSkin.ArenaRedBtn);
            this._operBtn1.visible = false;
            this._operBtn2 = ObjCreate.createGButton("退出同盟", 100, 183, 70, 26, this, GlobalSkin.ArenaRedBtn);
            this._operBtn2.visible = false;
            this._operBtn1.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClickHandler);
            this._operBtn2.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClickHandler);
            return;
        }

        /* internal  */onButtonClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GButton;
            var loc2=loc1.label;
            switch (loc2) 
            {
                case Language.getString(60856):
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildUnionLeave, this._guildInfo));
                    break;
                }
                case Language.getString(60857):
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildUnionDispose, this._guildInfo));
                    break;
                }
                case Language.getString(60858):
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildUnionShowInviteList, this._position));
                    break;
                }
                case Language.getString(60859):
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildUnionCancelInvite, {"guild": _guildInfo, "allocation": _allocate}));
                    break;
                }
            }
            return;
        }

        public updateRes(): void
        {
            if (!isDisposed) 
            {
                this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildUnionGuildBg);
                this._icon.setBitmapData(ImagesConst.GuildUnionIcon2);
                if (this._position == GuildUnionPosition.GuildUnionPositionOne) 
                {
                    this._mainBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildUnionMainGuild);
                }
            }
            return;
        }

        public updateInfo(arg1: int, arg2: int, arg3: SMiniGuildInfo): void
        {
            this._guildInfo = arg3;
            this._allocate = arg2;
            var loc1=Cache.instance.guildUnion.isMainGuild;
            if (this._position != GuildUnionPosition.GuildUnionPositionOne) 
            {
                if (arg1 != EGuildUnionStatus._EGuildUnionStatusNo) 
                {
                    if (arg1 != EGuildUnionStatus._EGuildUnionStatusApply) 
                    {
                        if (arg1 == EGuildUnionStatus._EGuildUnionStatusUnion) 
                        {
                            this._contentSp.visible = true;
                            this.updateGuildInfo(arg3, arg2);
                            this._guildName.htmlText = HTMLUtil.addColor(arg3.guildName, GlobalStyle.color6);
                            if (arg3.guildId != Cache.instance.guild.myGuildInfo.guildId) 
                            {
                                this.updateBtnStatus(0, "", "");
                            }
                            else 
                            {
                                this.updateBtnStatus(1, Language.getString(60856), "");
                            }
                        }
                    }
                    else 
                    {
                        this._contentSp.visible = true;
                        this.updateGuildInfo(arg3, arg2);
                        this._guildName.htmlText = HTMLUtil.addColor(arg3.guildName + Language.getString(60870), GlobalStyle.color6);
                        if (loc1) 
                        {
                            this.updateBtnStatus(1, Language.getString(60859), "");
                        }
                        else 
                        {
                            this.updateBtnStatus(0, "", "");
                        }
                    }
                }
                else 
                {
                    this._contentSp.visible = false;
                    if (loc1) 
                    {
                        this.updateBtnStatus(1, Language.getString(60858), "");
                    }
                    else 
                    {
                        this.updateBtnStatus(0, "", "");
                    }
                }
            }
            else 
            {
                this._contentSp.visible = true;
                this.updateGuildInfo(arg3, arg2);
                this._guildName.htmlText = HTMLUtil.addColor(arg3.guildName, GlobalStyle.color6);
                if (Cache.instance.guildUnion.hasUnion && loc1) 
                {
                    this.updateBtnStatus(1, Language.getString(60857), "");
                }
                else 
                {
                    this.updateBtnStatus(0, "", "");
                }
            }
            return;
        }

        /* internal  */updateGuildInfo(arg1: SMiniGuildInfo, arg2: int): void
        {
            this._leaderName.htmlText = HTMLUtil.addColor(Language.getString(60852) + " " + arg1.leaderName, GlobalStyle.color1);
            this._guildLevel.htmlText = HTMLUtil.addColor(Language.getString(60853) + " " + arg1.level, GlobalStyle.color1);
            this._menberNum.htmlText = HTMLUtil.addColor(Language.getString(60854) + " " + arg1.playerNum + "/" + arg1.maxPlayerNum, GlobalStyle.color1);
            this._incomeLocate.htmlText = HTMLUtil.addColor(Language.getString(60855) + " " + arg2, GlobalStyle.color6);
            return;
        }

        /* internal  */updateBtnStatus(arg1: int, arg2: string, arg3: string): void
        {
            if (arg1 != 1) 
            {
                if (arg1 != 2) 
                {
                    if (arg1 == 0) 
                    {
                        this._operBtn1.visible = false;
                        this._operBtn2.visible = false;
                    }
                }
                else 
                {
                    this._operBtn1.x = 16;
                    this._operBtn2.x = 100;
                    this._operBtn1.visible = true;
                    this._operBtn2.visible = true;
                    this._operBtn1.label = arg2;
                    this._operBtn2.label = arg3;
                }
            }
            else 
            {
                this._operBtn1.x = 58;
                this._operBtn1.visible = true;
                this._operBtn2.visible = false;
                this._operBtn1.label = arg2;
            }
            return;
        }

        /* internal */ /* var */_position: int;

        /* internal */ /* var */_mainBm: GBitmap;

        /* internal */ /* var */_bg: GBitmap;

        /* internal */ /* var */_icon: NormalBgItem;

        /* internal */ /* var */_contentSp: GSprite;

        /* internal */ /* var */_guildName: GTextFiled;

        /* internal */ /* var */_leaderName: GTextFiled;

        /* internal */ /* var */_guildLevel: GTextFiled;

        /* internal */ /* var */_menberNum: GTextFiled;

        /* internal */ /* var */_incomeLocate: GTextFiled;

        /* internal */ /* var */_operBtn1: GButton;

        /* internal */ /* var */_operBtn2: GButton;

        /* internal */ /* var */_guildInfo: SMiniGuildInfo;

        /* internal */ /* var */_allocate: int;
    }
